import logging

import pytest

from resource.pom.system_ui import SystemUI
from resource.pom.settings import Settings

class Test:
    system_ui = SystemUI
    setting = Settings

    @pytest.mark.parametrize('setup_teardown', [[setting.bundle_name]], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1、进入桌面，右上角下划进入控制中心，滑动亮度滚动条')
        device.start_ability(self.setting.bundle_name, self.setting.ability_name)
        device.click(*self.setting.display_brightness_item)
        device.set_brightness(10)
        device.dropdown_controller_center()
        device.refresh_layout()
        slider = device.get_element_by_type('Slider')
        x1, y1, x2, y2 = device.get_element_area(slider)
        y = (y1 + y2) // 2
        device.swipe(x1, y, x2, y)
        device.refresh_layout()
        slider_value1 = device.get_element_by_type('Slider').get('text')
        logging.info('预期结果1、滑动滚动条流畅，随实际情况变化，与设置的亮度条同样变化')
        # 收起控制中心
        device.swipe_up_dropdown_pan()
        device.refresh_layout()
        slider_value2 = device.get_element_by_type('Slider').get('text')
        assert int(float(slider_value1)) == int(float(slider_value2)), '亮度和设置中亮度不同步'
        # 再次呼出控制中心
        device.dropdown_controller_center()
        device.wait(1)
        device.swipe(x2, y, x1, y)
        device.refresh_layout()
        slider_value3 = device.get_element_by_type('Slider').get('text')
        device.swipe_up_dropdown_pan()
        device.refresh_layout()
        slider_value4 = device.get_element_by_type('Slider').get('text')
        assert int(float(slider_value3)) == int(float(slider_value4)), '亮度和设置中亮度不同步'